package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.vo.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Cyrus
 * @since 2020-12-07
 */
@Api(description = "课程分类服务")
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    //获取上传的文件，把文件内容都出来
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {
        //上传过来的excel
        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    //课程分类树形结构
    /**
     * {
     *     id:1,
     *     label:"一级分类"
     *     children:[
     *          id:2,
     *          label:"二级分类"
     *     ]
     */
    @GetMapping("getAllSubject")
    public R getAllSubject() {
        List<OneSubject> oneSubjects= subjectService.getAllOneTwoSubject();
        return R.ok().data("list",oneSubjects);
    }

//    @GetMapping("getOneSubject")
//    public R getOneSubject(){
//        List<EduSubject> list = subjectService.list(new QueryWrapper<EduSubject>().lambda().eq(EduSubject::getParentId, "0"));
//        return R.ok().data("oneList", list);
//    }
//
//    @GetMapping("getTwoSubject/{id}")
//    public R getTwoSubject(@PathVariable String id){
//        List<EduSubject> list = subjectService.list(new QueryWrapper<EduSubject>().lambda().eq(EduSubject::getParentId,id));
//        return R.ok().data("twoList", list);
//    }
}















